'use strict';
const notifier = require('node-notifier');
const path = require('path');

var _onClickListener = null;
var notify = {
    setOnClickListener: function(fn) {
        _onClickListener = fn;
        return this;
    },

    newMsg: function(msgs) {

        var totalCount = msgs.length;
        var iconPath = path.join(path.resolve(__dirname, '..', 'assets', 'icon'), 'Mailbox.icns');

        var options = {
        	'title':'新邮件',
            'message': '邮箱中有' + totalCount + '封未读',
            'icon': iconPath,
            'wait': true,
            'open':'http://qiye.163.com/login/?from=ym'
        };
        notifier.notify(options);

        notifier.on('click', function(notifierObject, options) {
            if (_onClickListener) {
                _onClickListener();
            }
        });
    }
}

module.exports = notify
